// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.jasmin.unit.memory;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class Latch {
  // (input/output, tristate) data bus
  public int DATA = 0;
  public int DATA_Z = 0;
  
  // (input, active high) write mode 
  public boolean WR = false;
  
  // (input, active high) request
  public boolean REQ = false;
  
  public int value = 0;
  
  public void update() {
    if (REQ) {
      if (WR) {
        DATA_Z = 0;
        value = DATA;
      } else {
        DATA_Z = ~0;
        DATA = value;
      }
    } else {
      DATA_Z = 0;
    }
  }
}
